package com.qfjy.controller;

import com.qfjy.client.VideoInfoFiegnClient;
import com.qfjy.entity.po.MeetingPub;
import com.qfjy.service.MeetingPubService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

@Controller
@Slf4j
@RequestMapping("meetingPub")
public class MeetingPubController {

    @Autowired
    private MeetingPubService meetingPubService;


    /**
     * TODO 根据会议编号查询会议信息  meetingPub/select?pcode=1111
     * @return
     */
    @ResponseBody
    @GetMapping("select")
    public Object selectMeetingPubByPcode(@RequestParam("pcode")String pcode){

       MeetingPub meetingPub= meetingPubService.selectMeetingPubByPcode(pcode);
       log.info("查询的是会议微服务信息：{}",meetingPub);

        /**
         * 调用视频微服务  服务间通信
         * http://localhost:8085/videoInfo/select?pcode=1698576761527459840
         */
       // RestTemplate原生： String url="http://localhost:8085/videoInfo/select?pcode="+pcode;
      //Ribbon+RestTemplate: 当Ribbon与Eureka配合使用时，
        // Ribbon可自动从Eureka Server获取服务提供者地址列表，并基于负载均衡算法，请求其中一个服务提供者实例
      //  String url="http://QF-VIDEO/videoInfo/select?pcode="+pcode;
      // String videoResult=restTemplate.getForObject(url,String.class);


        //Feign方式 调用 视频微服务
      String videoResult=videoInfoFiegnClient.selectVideoInfoByPcode(pcode);
       meetingPub.setRemark(videoResult);



       //要给的是一个ResultJson 统一内容格式（统一内容协议）
        return meetingPub;
    }

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private VideoInfoFiegnClient  videoInfoFiegnClient;
}
